<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学习相对定位</title>
    <style>
        /* 外部容器 */
        .container {
            width: 400px;
            height: 300px;
            background-color: #f9f9f9;
            border: 2px dashed #ccc;
            margin: 50px auto;
            position: relative;
        }

        /* 相对定位的元素 */
        .box {
            position: relative;
            width: 100px;
            height: 100px;
            background-color: #007bff;
            color: white;
            font-size: 14px;
            font-family: Arial, sans-serif;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 10px;
        }

        /* 不同偏移方式 */
        .box-1 {
            top: 20px;
            left: 20px;
        }

        .box-2 {
            top: -10px;
            left: 30px;
        }

        .box-3 {
            top: 40px;
            left: -50px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="box box-1">偏移 +20, +20</div>
    <div class="box box-2">偏移 -10, +30</div>
    <div class="box box-3">偏移 +40, -50</div>
</div>
</body>
</html>
